package com.rw.tool.util.random;

import java.util.Random;
import java.util.UUID;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

/**
 * 随机工具类
 */
public class RandomUtil {
    /**
     * 随机类
     */
    private static final Random RANDOM = new Random();

    private static final char[] LETTER = new char[]{
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
            'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B',
            'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
            'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
    };

    /**
     * 获取一个uuid
     */
    public static String uuid() {
        return UUID.randomUUID().toString();
    }

    public static int nextInt() {
        return RANDOM.nextInt();
    }

    public static int nextInt(int bound) {
        return RANDOM.nextInt(bound);
    }

    public static double nextDouble() {
        return RANDOM.nextDouble();
    }

    public static float nextFloat() {
        return RANDOM.nextFloat();
    }

    public static boolean nextBoolean() {
        return RANDOM.nextBoolean();
    }

    public static long nextLong() {
        return RANDOM.nextLong();
    }

    public static double nextGaussian() {
        return RANDOM.nextGaussian();
    }

    public static void nextBytes(byte[] bytes) {
        RANDOM.nextBytes(bytes);
    }

    public static IntStream ints() {
        return RANDOM.ints();
    }

    public static IntStream ints(long streamSize) {
        return RANDOM.ints(streamSize);
    }

    public static IntStream ints(long streamSize, int randomNumberOrigin, int randomNumberBound) {
        return RANDOM.ints(streamSize, randomNumberOrigin, randomNumberBound);
    }

    public static IntStream ints(int randomNumberOrigin, int randomNumberBound) {
        return RANDOM.ints(randomNumberOrigin, randomNumberBound);
    }

    public static LongStream longs() {
        return RANDOM.longs();
    }

    public static LongStream longs(long streamSize) {
        return RANDOM.longs(streamSize);
    }

    public static LongStream longs(long streamSize, int randomNumberOrigin, int randomNumberBound) {
        return RANDOM.longs(streamSize, randomNumberOrigin, randomNumberBound);
    }

    public static LongStream longs(int randomNumberOrigin, int randomNumberBound) {
        return RANDOM.longs(randomNumberOrigin, randomNumberBound);
    }

    public static char nextLetter() {
        return LETTER[RANDOM.nextInt(LETTER.length)];
    }

    public static Random getRandom() {
        return RANDOM;
    }
}
